# 设置请求头

import urllib.parse
import urllib.request

# url = 'https://www.baidu.com/s?wd=%E6%9D%8E%E7%99%BD'
base_url = 'https://www.baidu.com/s?'
name = urllib.parse.quote('李白')

# url = base_url + name

date = {
    'name': '李白',
    'age': 18,
    'address': '四川'
}

# urlEncode
url = base_url + urllib.parse.urlencode(date)

print(url)

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'
}
request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf8')

print(content)
